package model

import (
	"server/common"
	"server/pkg/app"
)

type HisCase struct {
	TestCaseID uint
	TestCase   TestCase

	Result     string `gorm:"column:result;not null;"`
	Err        string `gorm:"column:err;"`
	LogPath    string `gorm:"column:log_path;"`
	CostTime   uint   `gorm:"column:cost_time;"`
	Conclusion string `gorm:"column:conclusion;"`
}

func (c *HisCase) TableName() string {
	return "his_case"
}

func (c *HisCase) Create() error {
	if err := common.DB.Create(&c).Error; err != nil {
		return err
	}
	return nil
}

func (c *HisCase) List(page *app.Page) ([]HisCase, int64) {
	hiscases := []HisCase{}
	var count int64
	if err := common.DB.Order("starttime desc").Limit(page.Size).Offset((page.Page - 1) * page.Size).Find(&hiscases).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
		return hiscases, count
	}
	return hiscases, count
}
